home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / NET / IP_FIB.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  8KB  |  258 lines

  1. /*
  2.  * INET        An implementation of the TCP/IP protocol suite for the LINUX
  3.  *        operating system.  INET  is implemented using the  BSD Socket
  4.  *        interface as the means of communication with the user level.
  5.  *
  6.  *        Definitions for the Forwarding Information Base.
  7.  *
  8.  * Authors:    A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru>
  9.  *
  10.  *        This program is free software; you can redistribute it and/or
  11.  *        modify it under the terms of the GNU General Public License
  12.  *        as published by the Free Software Foundation; either version
  13.  *        2 of the License, or (at your option) any later version.
  14.  */
  15.  
  16. #ifndef _NET_IP_FIB_H
  17. #define _NET_IP_FIB_H
  18.  
  19. #include <linux/config.h>
  20.  
  21. struct kern_rta
  22. {
  23.     void        *rta_dst;
  24.     void        *rta_src;
  25.     int        *rta_iif;
  26.     int        *rta_oif;
  27.     void        *rta_gw;
  28.     u32        *rta_priority;
  29.     void        *rta_prefsrc;
  30.     struct rtattr    *rta_mx;
  31.     struct rtattr    *rta_mp;
  32.     unsigned char    *rta_protoinfo;
  33.     unsigned char    *rta_flow;
  34.     struct rta_cacheinfo *rta_ci;
  35. };
  36.  
  37. struct fib_nh
  38. {
  39.     struct device        *nh_dev;
  40.     unsigned        nh_flags;
  41.     unsigned char        nh_scope;
  42. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  43.     int            nh_weight;
  44.     int            nh_power;
  45. #endif
  46. #ifdef CONFIG_NET_CLS_ROUTE
  47.     __u32            nh_tclassid;
  48. #endif
  49.     int            nh_oif;
  50.     u32            nh_gw;
  51. };
  52.  
  53. /*
  54.  * This structure contains data shared by many of routes.
  55.  */
  56.  
  57. struct fib_info
  58. {
  59.     struct fib_info        *fib_next;
  60.     struct fib_info        *fib_prev;
  61.     int            fib_refcnt;
  62.     unsigned        fib_flags;
  63.     int            fib_protocol;
  64.     u32            fib_prefsrc;
  65.     u32            fib_priority;
  66. #define FIB_MAX_METRICS RTAX_RTT
  67.     unsigned        fib_metrics[FIB_MAX_METRICS];
  68. #define fib_mtu fib_metrics[RTAX_MTU-1]
  69. #define fib_window fib_metrics[RTAX_WINDOW-1]
  70. #define fib_rtt fib_metrics[RTAX_RTT-1]
  71.     int            fib_nhs;
  72. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  73.     int            fib_power;
  74. #endif
  75.     struct fib_nh        fib_nh[0];
  76. #define fib_dev        fib_nh[0].nh_dev
  77. };
  78.  
  79.  
  80. #ifdef CONFIG_IP_MULTIPLE_TABLES
  81. struct fib_rule;
  82. #endif
  83.  
  84. struct fib_result
  85. {
  86.     u32        *prefix;
  87.     unsigned char    prefixlen;
  88.     unsigned char    nh_sel;
  89.     unsigned char    type;
  90.     unsigned char    scope;
  91.     struct fib_info *fi;
  92. #ifdef CONFIG_IP_MULTIPLE_TABLES
  93.     struct fib_rule    *r;
  94. #endif
  95. };
  96.  
  97. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  98.  
  99. #define FIB_RES_NH(res)        ((res).fi->fib_nh[(res).nh_sel])
  100. #define FIB_RES_RESET(res)    ((res).nh_sel = 0)
  101.  
  102. #else /* CONFIG_IP_ROUTE_MULTIPATH */
  103.  
  104. #define FIB_RES_NH(res)        ((res).fi->fib_nh[0])
  105. #define FIB_RES_RESET(res)
  106.  
  107. #endif /* CONFIG_IP_ROUTE_MULTIPATH */
  108.  
  109. #define FIB_RES_PREFSRC(res)        ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
  110. #define FIB_RES_GW(res)            (FIB_RES_NH(res).nh_gw)
  111. #define FIB_RES_DEV(res)        (FIB_RES_NH(res).nh_dev)
  112. #define FIB_RES_OIF(res)        (FIB_RES_NH(res).nh_oif)
  113.  
  114. struct fib_table
  115. {
  116.     unsigned char    tb_id;
  117.     unsigned    tb_stamp;
  118.     int        (*tb_lookup)(struct fib_table *tb, const struct rt_key *key, struct fib_result *res);
  119.     int        (*tb_insert)(struct fib_table *table, struct rtmsg *r,
  120.                      struct kern_rta *rta, struct nlmsghdr *n,
  121.                      struct netlink_skb_parms *req);
  122.     int        (*tb_delete)(struct fib_table *table, struct rtmsg *r,
  123.                      struct kern_rta *rta, struct nlmsghdr *n,
  124.                      struct netlink_skb_parms *req);
  125.     int        (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
  126.                      struct netlink_callback *cb);
  127.     int        (*tb_flush)(struct fib_table *table);
  128.     int        (*tb_get_info)(struct fib_table *table, char *buf,
  129.                        int first, int count);
  130.     void        (*tb_select_default)(struct fib_table *table,
  131.                          const struct rt_key *key, struct fib_result *res);
  132.  
  133.     unsigned char    tb_data[0];
  134. };
  135.  
  136. #ifndef CONFIG_IP_MULTIPLE_TABLES
  137.  
  138. extern struct fib_table *local_table;
  139. extern struct fib_table *main_table;
  140.  
  141. extern __inline__ struct fib_table *fib_get_table(int id)
  142. {
  143.     if (id != RT_TABLE_LOCAL)
  144.         return main_table;
  145.     return local_table;
  146. }
  147.  
  148. extern __inline__ struct fib_table *fib_new_table(int id)
  149. {
  150.     return fib_get_table(id);
  151. }
  152.  
  153. extern __inline__ int fib_lookup(const struct rt_key *key, struct fib_result *res)
  154. {
  155.     if (local_table->tb_lookup(local_table, key, res) &&
  156.         main_table->tb_lookup(main_table, key, res))
  157.         return -ENETUNREACH;
  158.     return 0;
  159. }
  160.  
  161. extern __inline__ void fib_select_default(const struct rt_key *key, struct fib_result *res)
  162. {
  163.     if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
  164.         main_table->tb_select_default(main_table, key, res);
  165. }
  166.  
  167. #else /* CONFIG_IP_MULTIPLE_TABLES */
  168. #define local_table (fib_tables[RT_TABLE_LOCAL])
  169. #define main_table (fib_tables[RT_TABLE_MAIN])
  170.  
  171. extern struct fib_table * fib_tables[RT_TABLE_MAX+1];
  172. extern int fib_lookup(const struct rt_key *key, struct fib_result *res);
  173. extern struct fib_table *__fib_new_table(int id);
  174.  
  175. extern __inline__ struct fib_table *fib_get_table(int id)
  176. {
  177.     if (id == 0)
  178.         id = RT_TABLE_MAIN;
  179.  
  180.     return fib_tables[id];
  181. }
  182.  
  183. extern __inline__ struct fib_table *fib_new_table(int id)
  184. {
  185.     if (id == 0)
  186.         id = RT_TABLE_MAIN;
  187.  
  188.     return fib_tables[id] ? : __fib_new_table(id);
  189. }
  190.  
  191. extern void fib_select_default(const struct rt_key *key, struct fib_result *res);
  192.  
  193. #endif /* CONFIG_IP_MULTIPLE_TABLES */
  194.  
  195. /* Exported by fib_frontend.c */
  196. extern void        ip_fib_init(void);
  197. extern void        fib_flush(void);
  198. extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
  199. extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
  200. extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
  201. extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
  202. extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
  203.                    struct device *dev, u32 *spec_dst, u32 *itag);
  204. extern void fib_select_multipath(const struct rt_key *key, struct fib_result *res);
  205.  
  206. /* Exported by fib_semantics.c */
  207. extern int         ip_fib_check_default(u32 gw, struct device *dev);
  208. extern void        fib_release_info(struct fib_info *);
  209. extern int        fib_semantic_match(int type, struct fib_info *,
  210.                        const struct rt_key *, struct fib_result*);
  211. extern struct fib_info    *fib_create_info(const struct rtmsg *r, struct kern_rta *rta,
  212.                      const struct nlmsghdr *, int *err);
  213. extern int fib_nh_match(struct rtmsg *r, struct nlmsghdr *, struct kern_rta *rta, struct fib_info *fi);
  214. extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
  215.              u8 tb_id, u8 type, u8 scope, void *dst, int dst_len, u8 tos,
  216.              struct fib_info *fi);
  217. extern int fib_sync_down(u32 local, struct device *dev, int force);
  218. extern int fib_sync_up(struct device *dev);
  219. extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
  220.                    struct kern_rta *rta, struct rtentry *r);
  221. extern void fib_node_get_info(int type, int dead, struct fib_info *fi, u32 prefix, u32 mask, char *buffer);
  222. extern u32  __fib_res_prefsrc(struct fib_result *res);
  223.  
  224. /* Exported by fib_hash.c */
  225. extern struct fib_table *fib_hash_init(int id);
  226.  
  227. #ifdef CONFIG_IP_MULTIPLE_TABLES
  228. /* Exported by fib_rules.c */
  229.  
  230. extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
  231. extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
  232. extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
  233. extern u32 fib_rules_map_destination(u32 daddr, struct fib_result *res);
  234. #ifdef CONFIG_NET_CLS_ROUTE
  235. extern u32 fib_rules_tclass(struct fib_result *res);
  236. #endif
  237. extern u32 fib_rules_policy(u32 saddr, struct fib_result *res, unsigned *flags);
  238. extern void fib_rules_init(void);
  239. #endif
  240.  
  241. extern __inline__ void fib_combine_itag(u32 *itag, struct fib_result *res)
  242. {
  243. #ifdef CONFIG_NET_CLS_ROUTE
  244. #ifdef CONFIG_IP_MULTIPLE_TABLES
  245.     u32 rtag;
  246. #endif
  247.     *itag = FIB_RES_NH(*res).nh_tclassid<<16;
  248. #ifdef CONFIG_IP_MULTIPLE_TABLES
  249.     rtag = fib_rules_tclass(res);
  250.     if (*itag == 0)
  251.         *itag = (rtag<<16);
  252.     *itag |= (rtag>>16);
  253. #endif
  254. #endif
  255. }
  256.  
  257. #endif  _NET_FIB_H
  258.